# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=inkscape
pkgver=1.3.2
_pkgdate=2023-11-25
_pkgcommit=091e20ef0f
pkgrel=7
pkgdesc="Vector-based drawing program - svg compliant"
url="https://inkscape.org/"
arch="all"
license="GPL-2.0-or-later AND LGPL-2.1-or-later"
depends="
	adwaita-icon-theme
	desktop-file-utils
	py3-cssselect
	py3-lxml
	py3-numpy
	"
makedepends="
	boost-dev
	cmake
	dbus-dev
	font-dejavu
	gc-dev
	graphicsmagick-dev
	gtkmm3-dev
	gspell-dev
	lcms2-dev
	lib2geom-dev
	libcdr-dev
	libjpeg-turbo-dev
	libsoup-dev
	libtool
	libvisio-dev
	libxml2-dev
	libxslt-dev
	perl
	poppler-dev
	popt-dev
	potrace-dev
	python3-dev
	samurai
	"
checkdepends="
	bash
	gtest-dev
	imagemagick
	"
subpackages="
	$pkgname-dbg
	libinkscape_base
	$pkgname-doc
	$pkgname-tutorials::noarch
	$pkgname-lang
	$pkgname-view
	$pkgname-bash-completion
	$pkgname-minwaita::noarch
	$pkgname-icon-theme-tango:_icon_theme:noarch
	$pkgname-icon-theme-hicolor:_icon_theme:noarch
	$pkgname-icon-theme-multicolor:_icon_theme:noarch
	"
source="https://media.inkscape.org/dl/resources/file/inkscape-$pkgver.tar.xz
	include-missing-header-file.patch
	new-2geom.patch
	"
options="!check" # take extremely long and use absurd amounts of memory
ldpath="/usr/lib/inkscape"
builddir="$srcdir"/$pkgname-${pkgver}_${_pkgdate}_$_pkgcommit

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	# reduce size of debug syms
	CFLAGS="$CFLAGS -O2 -DNDEBUG -g1" \
	CXXFLAGS="$CXXFLAGS -Wno-deprecated-declarations -O2 -DNDEBUG -g1" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	INKSCAPE_DATADIR="$builddir/share" \
	PATH="$PATH:$PWD" ninja -C build check
}

package() {
	depends="libinkscape_base=$pkgver-r$pkgrel"
	DESTDIR="$pkgdir" cmake --install build
}

view() {
	pkgdesc="Viewing program for SVG files"
	depends="libinkscape_base=$pkgver-r$pkgrel"
	amove usr/bin/inkview
}

doc() {
	default_doc
	amove usr/share/inkscape/examples \
		usr/share/inkscape/doc \
		'usr/share/inkscape/*/LICENSE.txt' \
		'usr/share/inkscape/extensions/*/*/LICENSE.txt' \
		usr/share/inkscape/extensions/svg_fonts/OFL.txt
}

tutorials() {
	depends=
	pkgdesc="$pkgdesc (tutorials)"

	amove usr/share/inkscape/tutorials
}

minwaita() {
	depends=
	pkgdesc="$pkgdesc (minwaita theme)"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/share/inkscape/themes/Minwaita-Inkscape
}

_icon_theme() {
	name="${subpkgname#"$pkgname"-icon-theme-}"
	depends=
	pkgdesc="$pkgdesc ($name icon theme)"
	install_if="$pkgname=$pkgver-r$pkgrel"

	case "$name" in
		tango) name=Tango;;
	esac
	amove usr/share/inkscape/icons/"$name"
}

libinkscape_base() {
	depends=
	pkgdesc="base libinkscape_base.so to share with inkview"

	amove usr/lib/inkscape/libinkscape_base.so*
}

sha512sums="
a6da4b676ba3e7f954f95e3916ce78ce358b49c8052795a52d478064ef02eeae0337b0a94e89b9752ea6824a5758d28072c2bbf83f1e9ee28daebd3b0ef87343  inkscape-1.3.2.tar.xz
da6add9d8127db36c0ec0d63c69234e944b14241b668cc5bb4c1f2ec2d4b1eaea42ac32c91748c5944238a8ba9e456e83e19fdeaba90a5d2862d54793dfff783  include-missing-header-file.patch
14380c8df30d92aa1528f510f042dbe772a82ee7982d0b7de92d1987a10b8e95aca8023e14f12e51e91832ba0fa74dbfc6af9ca91b887f3a9179db0ce00a955a  new-2geom.patch
"
